﻿using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using Infragistics.Win.UltraWinTabbedMdi;
using Infragistics.Win.UltraWinToolbars;

namespace Cesave.Presentation.Permisos.WinForms.Client.ViewModels.Main
{
    public partial class MainViewModel
    {

        Dictionary<string, Form> _forms = new Dictionary<string, Form>();

        private void ClosingView(object sender, CancelableMdiTabEventArgs e)
        {
            string formName = e.Tab.Form.Name;
            if (_forms.ContainsKey(formName))
                _forms.Remove(formName);
        }

        private void HandleMenu(object sender, ToolClickEventArgs e)
        {
            Form form;
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            form = (Form)currentAssembly.CreateInstance(e.Tool.Key);
            if (form != null)
            {
                if (_forms.ContainsKey(form.Name))
                {
                    _forms[form.Name].Activate();
                }
                else
                {
                    form.MdiParent = _view;
                    form.Show();
                    _forms.Add(form.Name, form);
                }
            }
            if (e.Tool.Key == "Exit")
                System.Windows.Forms.Application.Exit();
        }
    }
}
